package com.neusoft.controller;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.neusoft.po.CommonResult;
import com.neusoft.po.Comment;
import com.neusoft.service.CommentService;

@RefreshScope
@RestController
@RequestMapping("/CommentController")
public class CommentController {

	@Autowired
	private CommentService commentService;

	@GetMapping("/listCommentByBusinessId/{businessId}")
	public CommonResult<List> listCommentByBusinessId(@PathVariable Integer businessId) {
		return new CommonResult(200, "success", commentService.listCommentByBusinessId(businessId));
	}

	@GetMapping("/listCommentByUserId/{userId}")
	public CommonResult<List> listCommentByUserId(@PathVariable String userId) {
		return new CommonResult(200, "success", commentService.listCommentByUserId(userId));
	}

	@GetMapping("/getCommentByOrderId/{orderId}")
	public CommonResult<Comment> getCommentByOrderId(@PathVariable Integer orderId) {
		return new CommonResult(200, "success", commentService.getCommentByOrderId(orderId));
	}

	@GetMapping("/getAverageRatingByBusinessId/{businessId}")
	public CommonResult<Double> getAverageRatingByBusinessId(@PathVariable Integer businessId) {
		return new CommonResult(200, "success", commentService.getAverageRatingByBusinessId(businessId));
	}

	@PostMapping("/createComment/{userId}/{businessId}/{orderId}/{commentContent}/{rating}/{isAnonymous}")
	public CommonResult<Integer> createComment(@PathVariable String userId, @PathVariable Integer businessId, @PathVariable Integer orderId,
			@PathVariable String commentContent, @PathVariable Integer rating, @PathVariable Boolean isAnonymous) {
		return new CommonResult(200, "success", commentService.saveComment(userId, businessId, orderId, commentContent, rating, isAnonymous));
	}

	@PutMapping("/updateComment/{commentId}/{commentContent}/{rating}/{isAnonymous}")
	public CommonResult<Integer> updateComment(@PathVariable Integer commentId, @PathVariable String commentContent, @PathVariable Integer rating, @PathVariable Boolean isAnonymous) {
		return new CommonResult(200, "success", commentService.updateComment(commentId,commentContent,rating,isAnonymous));
	}

	@DeleteMapping("/deleteComment/{commentId}")
	public CommonResult<Integer> deleteComment(@PathVariable Integer commentId) {
		return new CommonResult(200, "success", commentService.deleteComment(commentId));
	}
}